package com.cyzy.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Md5Utils {
    public static String md5(String input) {
        // 新建加密器
        MessageDigest md = null;
        StringBuilder sb = new StringBuilder();
        try {
            md = MessageDigest.getInstance("md5");
            byte[] digest = md.digest(input.getBytes()); // md5加密
            for (byte b : digest) {
                String hex = Integer.toHexString(b & 0xFF);
                if (hex.length() == 1) {
                    sb.append("0"); // 补齐位数
                }
                sb.append(hex);
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return sb.toString();
    }
}
